/*
 * @lc app=leetcode.cn id=713 lang=javascript
 *
 * [713] 乘积小于K的子数组
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
var numSubarrayProductLessThanK = function(nums, k) {
    if (nums.length == 0) return 0
    let i = 0, j = 0, ans = 0, mul = 1
    for (; j < nums.length; j++) {
        mul *= nums[j]
        while (mul >= k) {
            mul /= nums[i++]
        }
        ans += (j-i+1)
    }
    return ans < 0 ? 0 : ans
};
// @lc code=end

numSubarrayProductLessThanK([10,5,2,6], 100)